<?php
#+------------------------------------------------------------------
#| 普通的。
#+------------------------------------------------------------------
#| Author:Janmas Cromwell <janmas-cromwell@outlook.com>
#+------------------------------------------------------------------
namespace form\element\form;

class Tree extends Column
{

    protected $data    = [];
    protected $setting = [];

    public function setting($setting): self
    {
        $this->setting = $setting;
        return $this;
    }

    public function data(array $data = []): self
    {
        $this->data = $data;
        return $this;
    }

    protected function getData(): string
    {
        return json_encode($this->data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }

    protected function getSetting(): string
    {
        return is_array($this->setting) ? json_encode($this->setting, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $this->setting;
    }

    public function generate()
    {
        $label = $this->getLabel();
        $labelId = $this->getLabelFor();
        $labelClass = $this->getLabelClass();
        $name = $this->name;
        $class = $this->getClass();
        $id = $this->getId();
        $options = $this->getOptions();
        $data = $this->getData();
        $setting = $this->getSetting();

        $this->loadCss = [
            'http://libs.itshubao.com/zTree_v3/css/materialDesignStyle/materialdesign.css'
        ];

        $this->loadJs = [
            'http://libs.itshubao.com/zTree_v3/js/jquery.ztree.all.min.js'
        ];

        $this->js = <<<HTML

$(document).ready(function(){
    $.fn.zTree.init($("#$labelId"), $setting, $data);
});

HTML;

        return <<<HTML

 <ul id="$labelId" class="ztree"></ul>

HTML;

    }

    /**
     * @inheritDoc
     */
    protected function normal()
    {
        // TODO: Implement normal() method.
    }

    /**
     * @inheritDoc
     */
    protected function vertical()
    {
        // TODO: Implement vertical() method.
    }

    /**
     * @inheritDoc
     */
    protected function inline()
    {
        // TODO: Implement inline() method.
    }
}